ifeq ($(_THEOS_RULES_LOADED),)
include $(THEOS_MAKE_PATH)/rules.mk
endif

.PHONY: internal-bundle-all_ internal-bundle-stage_ internal-bundle-compile

AUXILIARY_LDFLAGS += -dynamiclib

ifeq ($(_THEOS_MAKE_PARALLEL_BUILDING), no)
internal-bundle-all_:: $(_OBJ_DIR_STAMPS) $(THEOS_OBJ_DIR)/$(THEOS_CURRENT_INSTANCE)
else
internal-bundle-all_:: $(_OBJ_DIR_STAMPS)
	$(ECHO_NOTHING)$(MAKE) --no-print-directory --no-keep-going \
		internal-bundle-compile \
		_THEOS_CURRENT_TYPE=$(_THEOS_CURRENT_TYPE) THEOS_CURRENT_INSTANCE=$(THEOS_CURRENT_INSTANCE) _THEOS_CURRENT_OPERATION=compile \
		THEOS_BUILD_DIR="$(THEOS_BUILD_DIR)" _THEOS_MAKE_PARALLEL=yes$(ECHO_END)

internal-bundle-compile: $(THEOS_OBJ_DIR)/$(THEOS_CURRENT_INSTANCE)
endif

ifneq ($(OBJ_FILES_TO_LINK),)

$(eval $(call _THEOS_TEMPLATE_NOWARNING_LINKING_RULE,$(THEOS_CURRENT_INSTANCE)))

else # OBJ_FILES_TO_LINK == ""

$(THEOS_OBJ_DIR)/$(THEOS_CURRENT_INSTANCE):
	$(NOTICE_EMPTY_LINKING)

endif # OBJ_FILES_TO_LINK


ifeq ($($(THEOS_CURRENT_INSTANCE)_BUNDLE_NAME),)
LOCAL_BUNDLE_NAME = $(THEOS_CURRENT_INSTANCE)
else
LOCAL_BUNDLE_NAME = $($(THEOS_CURRENT_INSTANCE)_BUNDLE_NAME)
endif

ifeq ($($(THEOS_CURRENT_INSTANCE)_BUNDLE_EXTENSION),)
LOCAL_BUNDLE_EXTENSION = bundle
else
LOCAL_BUNDLE_EXTENSION = $($(THEOS_CURRENT_INSTANCE)_BUNDLE_EXTENSION)
endif

THEOS_SHARED_BUNDLE_RESOURCE_PATH = $(THEOS_STAGING_DIR)$($(THEOS_CURRENT_INSTANCE)_INSTALL_PATH)/$(LOCAL_BUNDLE_NAME).$(LOCAL_BUNDLE_EXTENSION)
include $(THEOS_MAKE_PATH)/instance/shared/bundle.mk

internal-bundle-stage_:: shared-instance-bundle-stage
	$(ECHO_NOTHING)mkdir -p "$(THEOS_SHARED_BUNDLE_RESOURCE_PATH)"$(ECHO_END)
ifneq ($(OBJ_FILES_TO_LINK),)
	$(ECHO_NOTHING)cp $(THEOS_OBJ_DIR)/$(THEOS_CURRENT_INSTANCE) "$(THEOS_SHARED_BUNDLE_RESOURCE_PATH)"$(ECHO_END)
endif

$(eval $(call __mod,instance/bundle.mk))
